package main

import (
	"bufio"
	"fmt"
	"math/rand"
	"os"
	"strconv"
	"strings"
	"time"
)

func main() {
	maxNumber := 100
	rand.Seed(time.Now().UnixNano())
	secretNumber := rand.Intn(maxNumber)

	for {
		fmt.Println("Please input your guess")
		reader := bufio.NewReader(os.Stdin)
		input, err := reader.ReadString('\n')

		if err != nil {
			fmt.Println("An error occured while input your guess. Please try again.")
			continue
		}

		//input = strings.TrimSuffix(input, "\r\n") // windows
		input = strings.TrimSuffix(input, "\n")

		guess, err := strconv.Atoi(input)

		if err != nil {
			fmt.Println("Invalid input! Please try again.")
			continue
		}

		if guess > secretNumber {
			fmt.Println("Your guess is bigger than the secret number! Please try again.")
		} else if guess < secretNumber {
			fmt.Println("Your guess is smaller than the secret number! Please try again.")
		} else {
			fmt.Println("Correct, you Legend!")
			break
		}

	}
}
